package com.wisdytech.linkdcs.equipLifeCycle.malfunction.action;


import com.wisdytech.common.handler.ResourceMatchingService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageInfo;
import com.wisdytech.common.bean.Filter;
import com.wisdytech.common.bean.StandardResult;
import com.wisdytech.common.bean.StandardTableResult;
import com.wisdytech.common.utils.BaseUtil;
import com.wisdytech.linkdcs.equipLifeCycle.check.vo.CheckRecordVo;
import com.wisdytech.linkdcs.equipLifeCycle.malfunction.dto.MalfunctionSearchDto;
import com.wisdytech.linkdcs.equipLifeCycle.malfunction.model.MalfunctionRecord;
import com.wisdytech.linkdcs.equipLifeCycle.malfunction.service.IMalfunctionRecordService;
import com.wisdytech.linkdcs.equipLifeCycle.malfunction.vo.MRegisterVo;
import com.wisdytech.linkdcs.equipLifeCycle.malfunction.vo.MalfunctionVo;
import com.wisdytech.linkdcs.system.model.SysUser;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author dailibo
 * @since 2018-06-11
 */
@Controller
@RequestMapping("/equipLifeCycle/malfunction/record")
public class MalfunctionRecordController {

	private Logger logger =LoggerFactory.getLogger(getClass());
	
	@Autowired
	private IMalfunctionRecordService iMalfunctionRecordService;
    @Autowired
    @Qualifier("resourceMatchingService")
    private ResourceMatchingService resourceMatchingService;
	@RequestMapping("register/index")
	public String recoredRegisterIndex(Model model, HttpServletRequest httpRequest){
        this.resourceMatchingService.getResourceName(httpRequest,model);
		return "lifeCycle/equipLifeCycle/malfunction/register";
	}
	
	@RequestMapping("index")
	public String recoredIndex(Model model, HttpServletRequest httpRequest){
        this.resourceMatchingService.getResourceName(httpRequest,model);
		return "lifeCycle/equipLifeCycle/malfunction/record";
	}
	
	@RequestMapping("/listRecords/get.mvc")
	@ResponseBody
	public StandardTableResult<MalfunctionVo> listRecords(Filter filter,MalfunctionSearchDto dto){
		
		PageInfo<MalfunctionVo>  pageInfo =
				iMalfunctionRecordService.selectAllMalfunctionLists(filter, dto);
		StandardTableResult<MalfunctionVo> tables=
				new StandardTableResult<MalfunctionVo>(pageInfo.getTotal(),pageInfo.getList());
		
		return tables;
	}
	
	@PostMapping("/registerRecord/add.mvc")
	@ResponseBody
	public StandardResult registerRecord(MalfunctionRecord record) {
		SysUser user =BaseUtil.getCurrentUser();
		return iMalfunctionRecordService.add(record, user.getUsername())?
				StandardResult.getSuccessResult():
					StandardResult.getFailResult("保存失败");
	}
	
	@RequestMapping("/submint/update.mvc")
	@ResponseBody
	public StandardResult submitRecord(String recordIds) {
		SysUser user =BaseUtil.getCurrentUser();
		return iMalfunctionRecordService.submint(recordIds, user.getUsername())?
				StandardResult.getSuccessResult():
					StandardResult.getFailResult("保存失败");
	}
	
	@RequestMapping("/getRegisterRecord/get.mvc")
	@ResponseBody
	public StandardResult getRegisterRecord(String pkId) {
		MRegisterVo  record =iMalfunctionRecordService.getRecordById(pkId);
		
		
		if(null != record) {
			return StandardResult.getSuccessResult(record);
		}else {
			return StandardResult.getFailResult();
		}
	}
	
	
	
	
}

